package edu.cug.water.visual.modules.dataset.controller;

import edu.cug.water.visual.common.utils.PageUtils;
import edu.cug.water.visual.common.utils.R;
import edu.cug.water.visual.modules.dataset.entity.DatasetEntity;
import edu.cug.water.visual.modules.dataset.service.DatasetService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-10-30 19:31:57
 */
@RestController
@RequestMapping("dataset")
public class DatasetController {
    @Autowired
    private DatasetService datasetService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("generator:dataset:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = datasetService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("generator:dataset:info")
    public R info(@PathVariable("id") Long id){
		DatasetEntity dataset = datasetService.getById(id);

        return R.ok().put("dataset", dataset);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("generator:dataset:save")
    @RequiresAuthentication
    public R save(@RequestBody DatasetEntity dataset){
        Long id = datasetService.saveAndReturn(dataset);
        return R.ok().put("id", id);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:dataset:update")
    public R update(@RequestBody DatasetEntity dataset){
		datasetService.updateById(dataset);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("generator:dataset:delete")
    public R delete(@RequestBody Long[] ids){
		datasetService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
